package br.ufrn.opencopi.util;

import java.util.Hashtable;
import java.util.List;

import org.jdom.Document;

import org.jdom.Element;

import org.jdom.input.SAXBuilder;

/**
 * Essa classe l� o arquivo XML de configuracao de pesos dos parametros de
 * qualidade
 * 
 * @author fredlopes
 * 
 */
public class XMLReader {

	@SuppressWarnings("unchecked")
	public static Hashtable<String, Double> getParametersWeight() {

		Hashtable<String, Double> qualityParametersWeight = new java.util.Hashtable<String, Double>();

		Document doc = null;

		SAXBuilder builder = new SAXBuilder();

		try {
			doc = builder.build("qualityParameterWeights.xml");

		} catch (Exception e) {

			e.printStackTrace();
		}

		Element parameters = doc.getRootElement();

		List<Element> lista = parameters.getChildren();

		for (Element e : lista) {
			qualityParametersWeight.put(e.getChildText("name"),
					Double.parseDouble(e.getChildText("weight")));
		}

		return qualityParametersWeight;
	}

}
